package cn.doitedu.demo.functions;

import org.apache.flink.streaming.api.CheckpointingMode;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

import java.time.ZoneId;

public class Function内建函数 {

    public static void main(String[] args) {

        // 构造stream api 编程的环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.enableCheckpointing(5000, CheckpointingMode.EXACTLY_ONCE);
        env.getCheckpointConfig().setCheckpointStorage("file:///d:/ckpt");

        // 构造 sql 编程环境
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
        tenv.getConfig().setLocalTimeZone(ZoneId.of("Asia/Shanghai"));


        //tenv.executeSql("select upper('abc') ").print();
        //tenv.executeSql("select 3<>4").print();
        //tenv.executeSql("select true or false ").print();
        //tenv.executeSql("select 3<>4 OR 4>5 ").print();
        //tenv.executeSql(" select not 4>3").print();
        //tenv.executeSql(" select ceil(-3.1)").print();
        //tenv.executeSql(" select rand_integer(10,20),rand_integer(10,20),rand_integer(10,20)").print();
        //tenv.executeSql(" select lpad('8',5,'x')").print();
        //tenv.executeSql(" select DATE '2024-01-12' ").print();
        tenv.executeSql(
                " SELECT " +
                        "UNIX_TIMESTAMP('2024/01/12 09:49:30','yyyy/MM/dd HH:mm:ss' )  ntz," +  // 日历时间按东8转绝对时间, 会-8小时
                        " UNIX_TIMESTAMP('2024/01/12 09:49:30 +0000','yyyy/MM/dd HH:mm:ss X' ) tz ") // 日历时间按UTC转绝对时间，会-0小时
                .print();

        tenv.executeSql(
                " SELECT TO_TIMESTAMP_LTZ(1705024170000,3) ntz," +  //绝对时间按东8,转日历，会+8小时再转：  2024-01-12 09:49:30.000
                " TO_TIMESTAMP_LTZ(1705052970000,3) tz ").print();  // 绝对时间按东8，转日历，会+8小时再转：2024-01-12 17:49:30.000


        //tenv.executeSql(" SELECT to_timestamp_ltz(1705024170000,3)").print();


    }
}
